// input 50a6we8y20x


function extandStr(str) {
    let num = "";
    let res = "";
    let curStr = "";
    for (let i = 0; i < str.length; i++) {
        if (str[i] >= "0" && str[i] <= "9") num += str[i];
        else if (i + 1 < str.length && str[i + 1] >= "0" && str[i + 1] <= "9") {
            curStr += str[i];
            num = parseInt(num);
            res += curStr.repeat(num);
            console.log(num, curStr);
            num = "";
            curStr = "";
        } else {
            curStr += str[i];
        }
    }
    // 最后一组的处理 因为最后一组以字母结尾 走不到下一个数字
    if(curStr && num){
        res += curStr.repeat(parseInt(num));
    }
    return res;
}

console.log(extandStr("10a6we8y10x"));
console.log(print("10a6we8y10x"));

// 正则解法
function print(str){
    return String(str).replace(/(\d+)([a-zA-Z]+)/g,function(_, number, string){
        return string.repeat(number);
    })
}
